package com.yaofeng.mybatis.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 自动填充器
 * Created by yaofeng on 2019/8/30.
 */
@Component
@Slf4j
public class MyMetaObjectHandler implements MetaObjectHandler {


    @Override
    public void insertFill(MetaObject metaObject) {
      log.info("start insert fill ....");
      this.setInsertFieldValByName("createTime",LocalDateTime.now(),metaObject);
      this.setInsertFieldValByName("updateTime",LocalDateTime.now(),metaObject);
      this.setInsertFieldValByName("createUserId",1167344886682865665L,metaObject);
      this.setInsertFieldValByName("updateUserId",1167344886682865665L,metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start update fill ....");
        this.setUpdateFieldValByName("updateTime",LocalDateTime.now(),metaObject);
        this.setUpdateFieldValByName("updateUserId",1167344886682865665L,metaObject);
    }
}
